package com.wangyk.rabbitmqconsole;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class LogUtil
{
    private static Logger logger = LogManager.getLogger(LogUtil.class);

    public static void initLogEnv(String appName,String hostIp)
    {
        ThreadContext.put("hostname", appName);
        ThreadContext.put("appname", hostIp);
    }

    public static String getHostAddress()
    {
        InetAddress addr;
        try
        {
            addr = InetAddress.getLocalHost();
            String ip = addr.getHostAddress().toString(); // 获取本机ip
            // String hostName = addr.getHostName().toString(); // 获取本机计算机名称
            return ip;
        }
        catch (UnknownHostException e)
        {
            logger.error(e.getMessage(), e);
            return "";
        }

    }
}
